package cn.gailvlun.gll.presentation.hotel.night

import android.content.Context
import android.content.Intent
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.view.View
import cn.gailvlun.gll.R
import cn.gailvlun.gll.databinding.ActivityHotelBrowseBinding
import cn.gailvlun.gll.net.hotel.InsomniaHotel
import cn.gailvlun.gll.net.hotel.InsomniaType
import cn.gailvlun.gll.presentation.base.BaseActivity
import cn.gailvlun.gll.util.ReportUtil






class HotelBrowseActivity : BaseActivity() {

    companion object {
        fun openActivity(context: Context, insomniaType: InsomniaType = InsomniaType.T) {
            val intent = Intent(context, HotelBrowseActivity::class.java)
            intent.putExtra("insomniaType", insomniaType)
            context.startActivity(intent)
        }
    }

    private lateinit var mBinding: ActivityHotelBrowseBinding
    private lateinit var mPagerAdapter: HotelBrowsePagerAdapter

    override fun initComponent() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_hotel_browse)
        mBinding.presenter = Presenter()

        val insomniaType = intent.getSerializableExtra("insomniaType") as InsomniaType

        mPagerAdapter = HotelBrowsePagerAdapter(supportFragmentManager, insomniaType)
        mBinding.nsvp.adapter = mPagerAdapter

        mBinding.nsvp.offscreenPageLimit = 3

        mBinding.stl.setViewPager(mBinding.nsvp)

    }

    override fun createHandler() {
        mBinding.ivBack.setOnClickListener { onBackPressed() }
    }

    override fun loadData(savedInstanceState: Bundle?) {
    }

    inner class Presenter {
        fun onComment(item: InsomniaHotel?) {
            if (item != null) {
                
                HotelCommentActivity.openActivity(mContext, item.id)
            }
        }

        fun report(view: View) {
            ReportUtil(mContext).show()
        }
    }

    fun changeAllSubscribe(item: InsomniaHotel) {
        mPagerAdapter.changeAllSubscribe(item)
    }

}